package com.seio.edc.console;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import com.nova.edc.model.energy.BillStatistics;
import com.nova.edc.service.energy.BillStatisticsService;
import com.seio.edc.util.DateTimeUtil;

public class TaskStatistics {

	private Logger log = Logger.getLogger(TaskStatistics.class);
	@Autowired
	private BillStatisticsService novaBillStatisticsService;

	@Value("#{cloudDataProperties['statistics_min_date']}")
	private String statisticsMinDate;

	@Value("#{cloudDataProperties['statistics_max_date']}")
	private String statisticsMaxDate;

	public void execute() {
		log.info("云平台每日数据统计任务开始："
				+ DateTimeUtil.getNowTime(DateTimeUtil.YYYY_MM_DD_HH_MM_SS));
		List<BillStatistics> billStatistics = novaBillStatisticsService
				.getStatisticsByDay(
						DateTimeUtil.addDays(-1, DateTimeUtil.YYYY_MM_DD),
						DateTimeUtil.addDays(-1, DateTimeUtil.YYYY_MM_DD));
		novaBillStatisticsService.insert(billStatistics);
		log.info("云平台每日数据统计任务结束："
				+ DateTimeUtil.getNowTime(DateTimeUtil.YYYY_MM_DD_HH_MM_SS));
	}

	public void executeHistory() {
		log.info("云平台历史数据统计任务开始："
				+ DateTimeUtil.getNowTime(DateTimeUtil.YYYY_MM_DD_HH_MM_SS));
		List<BillStatistics> billStatistics = novaBillStatisticsService
				.getStatisticsByDay(statisticsMinDate, statisticsMaxDate);
		if (billStatistics != null && billStatistics.size() > 0) {
			novaBillStatisticsService.insert(billStatistics);
		}
		log.info("云平台历史数据统计任务结束："
				+ DateTimeUtil.getNowTime(DateTimeUtil.YYYY_MM_DD_HH_MM_SS));
	}

}
